package com.atguigu.spring.config;

import com.atguigu.spring.condition.LinuxCondition;
import com.atguigu.spring.condition.WindowsCondition;
import com.atguigu.spring.entity.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

@Configuration
public class UserBeanConfig {

    // Condition 类中设定的条件成立时，bean 对象才加入 IOC 容器
    @Conditional(WindowsCondition.class)
    @Bean(name = "bill")
    public User user1() {
      return new User("Bill Gates", 62);
    }

    @Conditional(LinuxCondition.class)
    @Bean(name = "linus")
    public User user2() {
      return new User("Linus", 48);
    }
}